#include "wangge.h"
#include "ui_wangge.h"
#include "QPainter"
#include "math.h"
wangge::wangge(QWidget *parent) :
    QDialog(parent)//,
 //   ui(new Ui::wangge)
{
    resize(600,600);
    int i=0;
   // ui->setupUi(this);
    for(i=0;i<20;i++)
    {
         x[i]=20*i;
         y[i]=rand()%100;
    }
    this->startTimer(500);
}

wangge::~wangge()
{
    //delete ui;
}

void wangge::timerEvent(QTimerEvent *)
{
    int i=0;
    for(i=0;i<19;i++)
    {
        x[i]=20*i;
        y[i]=y[i+1];
    }
    srand((unsigned)time(NULL));
    y[19]=rand()%100;
    this->repaint();
}
void wangge::paintEvent(QPaintEvent *)
{
    int i=0,j=0;
    //int a,b,c,d;
    srand((unsigned)time(NULL));
    /*for(j=0;j<=100;j++)
    {
        suiji[j]=rand()%100;
    }*/
    QPainter painter(this);
    QPen pen(Qt::SolidLine);

    painter.setPen(pen);
    painter.drawLine(0,0,0,400);
    painter.drawLine(0,400,400,400);
    /*QPen pen(Qt::DotLine);*/
    pen.setStyle(Qt::DotLine);
    pen.setColor(QColor(255, 0, 0, 127));
    painter.setPen(pen);
    for(i=40;i<=400;i+=40)
    {
        painter.drawLine(0,i,400,i);
    }
    for(i=40;i<=400;i+=40)
    {
        painter.drawLine(i,0,i,400);
    }
    pen.setStyle(Qt::SolidLine);
    pen.setColor(QColor(255,56,23,127));
    pen.setWidth(4);
    painter.setPen(pen);
    for(j=0;j<19;j++)
    {
        painter.drawLine(x[j],y[j],x[j+1],y[j+1]);
    }

}
